<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>12.应用</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            height: 2000px;
        }
        .box{
            width: 600px;
            height: 300px;
            background-color: pink;
        }
        .small{
            position: relative;
            top: 0;
            left:0;
            width: 60px;
            height: 30px;
            background-color: brown;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="small"></div>
    </div>
</body>
<script>
    var small=document.getElementsByClassName('small')[0];
    document.body.onclick=function(e){
        small.style.top=e.pageY+'px';
        small.style.left=e.pageX+'px';
    }
</script>
</html>